package com.mornd.gulimall.order.receiver;

import com.mornd.gulimall.order.entity.Order;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author: mornd
 * @dateTime: 2023/8/21 - 19:26
 */

@Slf4j
@Component
public class TestReceiver {

    @RabbitHandler
    @RabbitListener(queues = {"q3"})
    public void listen(Message message, Order order, Channel channel) {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        log.info("接收到消息：{},{},order：{}", deliveryTag, message, order);

        try {
            // 手动确认
            channel.basicAck(deliveryTag, false);
//            channel.basicNack(deliveryTag, false, false);
//            channel.basicReject(deliveryTag, false);
        } catch (IOException e) {
            log.error(e.getMessage());
        }
    }

}
